package es.unileon.prg2.censo.iterator;

/**
 * @author Manuel Molinos Crespo, Adrian Campazas Vega, Alberto Castro Delgado, Pedro Alvarez Alvarez, Adrian Cabello Galvan, Jose Alvaro Fernandez Alvarez
 *
 */
import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import es.unileon.prg2.censo.adapter.Aggregate;
import es.unileon.prg2.censo.adapter.ArrayListAggregate;
import es.unileon.prg2.censo.adapter.ArrayListAggregate;
import es.unileon.prg2.censo.composite.*;
import es.unileon.prg2.censo.exception.CensoException;
import es.unileon.prg2.censo.handler.DNICitizen;

public class TreeIterator implements Iterador {
	static Logger logger = Logger.getLogger(DNICitizen.class.getName());

	private Aggregate aggregate;
	private int position;
	private ArrayListAggregate<Component> element = new ArrayListAggregate<Component>();

	/**
	 * Constructor used to created an Iterator that catch all components into of the ArrayList.
	 * @param boss ArrayList with all components of the censo
	 */
	public TreeIterator(Aggregate aggregate) {
		PropertyConfigurator.configure("etc/log4j.properties");

		this.position = 0;	
		this.aggregate = aggregate;
	}
	
	@Override
	public void firstElement() {
		this.position = 0;
	}
	
	public int getPosition() {
		return this.position;
	}

	@Override
	public void nextElement() throws CensoException {
		if (this.hasmoreElements() == true) {
			this.position++;
		} else {
			StringBuffer message = new StringBuffer();
			message.append("Haven't more elements in this tree.");
			logger.error("Haven't more elements in this tree.");

			if (message.length() != 0) {
				throw new CensoException(message.toString());
			}
		}
	}


	@Override
	public boolean hasmoreElements() throws CensoException {
		return this.position < aggregate.getSize();
	}

	@Override
	public Object currentElement() {
		return aggregate.getElement(this.position);
	}

	@Override
	public int getMax() {
		return 0;
	}

	@Override
	public int getSizeIterator() {
		return 0;
	}

	@Override
	public int getMin() {
		return 0;
	}

	@Override
	public void setMin(int i) {
		
	}

	@Override
	public void setMax(int i) {
		
	}
	
	
}
